package com.lsfb.signsys.compatible;

import com.lsfb.signsys.ApiException;

import retrofit2.HttpException;

/**
 * Created by zgscwjm on 2018/3/27.
 */

public class ExceptionEngine {

    //对应HTTP的状态码
//    private static final int UNAUTHORIZED = 401;
//    private static final int FORBIDDEN = 403;
//    private static final int NOT_FOUND = 404;
//    private static final int REQUEST_TIMEOUT = 408;
//    private static final int INTERNAL_SERVER_ERROR = 500;
//    private static final int BAD_GATEWAY = 502;
//    private static final int SERVICE_UNAVAILABLE = 503;
//    private static final int GATEWAY_TIMEOUT = 504;


    public static ApiException handleException(Throwable e) {
        ApiException ex;
        if (e instanceof ApiException) {             //HTTP错误
            ex = (ApiException)e;
//            HttpException httpException = (HttpException) e;
//            ex = new ApiException(e, 400);
//            switch (httpException.code()) {
//                case UNAUTHORIZED:
//                case FORBIDDEN:
//                case NOT_FOUND:
//                case REQUEST_TIMEOUT:
//                case GATEWAY_TIMEOUT:
//                case INTERNAL_SERVER_ERROR:
//                case BAD_GATEWAY:
//                case SERVICE_UNAVAILABLE:
//                default:
//                    ex.setDisplayMessage("网络错误");  //均视为网络错误
//                    break;
//            }
//            return ex;
        }else {
            ex = new ApiException(1000,"未知错误");
        }
        return ex;
    }
}
